package scm.erp.core.domain;

import scm.erp.core.enums.RetCodeEnum;
import lombok.Data;

@Data
public class Ret<T> {
    public static final Integer SUCCESS_RET_CODE = 200;
    public static final String SUCCESS_RET_MSG = "操作成功";
    private RetCodeEnum retCode;
    private String retMsg;
    private T retData;

    public Ret(RetCodeEnum retCode, String retMsg, T retData) {
        this.retCode = retCode;
        this.retMsg = retMsg;
        this.retData = retData;
    }

    public static <T> Ret<T> ok() {
        return new Ret<>(RetCodeEnum.OK,
                "业务操作成功!",
                null);
    }

    public static <T> Ret<T> ok(T data) {
        return new Ret<>(RetCodeEnum.OK, "业务操作成功!", data);
    }

    public static <T> Ret<T> ok(T data, String msg) {
        return new Ret<>(RetCodeEnum.OK, msg, data);
    }

    public static <T> Ret<T> fail() {
        return new Ret<>(RetCodeEnum.FAIL, "业务操作失败!", null);
    }

    public static <T> Ret<T> fail(String msg) {
        return new Ret<>(RetCodeEnum.FAIL, msg, null);
    }

    public static <T> Ret<T> fail(T data) {
        return new Ret<>(RetCodeEnum.FAIL, "业务操作失败!", data);
    }

    public static <T> Ret<T> fail(T data, String msg) {
        return new Ret<>(RetCodeEnum.FAIL, msg, data);
    }

    public static <T> Ret<T> fail(RetCodeEnum code, String msg) {
        return new Ret<>(code, msg, null);
    }

    public static <T> Ret<T> fail(RetCodeEnum code, String msg, T data) {
        return new Ret<>(code, msg, data);
    }
}